<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="csrf-token" content="{{csrf_token()}}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />


    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/font.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/xadmin.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/lib/layui/css/layui.css')}}">


    <script src="{{URL::asset('resources/xadmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{URL::asset('resources/xadmin/js/xadmin.js')}}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<div class="x-nav">
          <span class="layui-breadcrumb">
            <a><cite></cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>

<div class="layui-fluid layui-container" >



            {{--<div class="layui-col-xs6">--}}
                {{--<div class="layui-bg-cyan">6/12</div>--}}
            {{--</div>--}}
            {{--<div class="layui-col-xs6">--}}
                {{--<div class="layui-bg-blue">6/12</div>--}}
            {{--</div>--}}

        {{--<div class="layui-row">--}}
            {{--<div class="layui-col-xs3" style="background-color: #EEEEEE">--}}
                {{--<div class="grid-demo grid-demo-bg1">3/12</div>--}}
            {{--</div>--}}
            {{--<div class="layui-col-xs6">--}}
                {{--<div class="layui-bg-blue">6/12</div>--}}
            {{--</div>--}}
            {{--<div class="layui-col-xs3">--}}
                {{--<div class="grid-demo">3/12</div>--}}
            {{--</div>--}}
        {{--</div>--}}

    <div class="layui-row ">
        {{--layui-col-md6--}}
        <div class="layui-col-xs2" style="background-color: #EEEEEE">
            <div class="grid-demo grid-demo-bg1">.</div>
        </div>
        <form class="layui-form layui-col-xs10" >



            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="mail" required="" lay-verify="required"
                          value="{{Auth::guard('admin')->user()->email}}" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*请检查您的邮箱是否正确，不是请修改</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <h2>请选择您要订阅的邮件选项</h2>

            </div>

            <!-- 这里title是在网页上显示的数据，value是用Ajax发送的实际的值 -->
            <div class="layui-form-item">
                <label class="layui-form-label">可多选</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="danger_mail" title="危险值警报"checked>
                    <input type="checkbox" name="month_mail" title="月数据分析" >
                    <input type="checkbox" name="info_mail" title="网站反馈调查推送">
                </div>
            </div>

            <div class="layui-input-item">
                {{--<div class="layui-input-inline">--}}
                    {{--<label class="layui-form-label">.</label>--}}
                    {{--<div class="layui-input-block">--}}
                        {{--<input type="checkbox" name="status" lay-skin="switch" lay-text="启用|不启用">--}}
                    {{--</div>--}}
                {{--</div>--}}
                <div class="layui-input-inline">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button type="reset" class="layui-btn-lg layui-btn-primary">重置</button>
                </div>
                <div class="layui-input-inline">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn layui-btn-lg" lay-filter="add" lay-submit="">
                        提交
                    </button>
                </div>
            </div>

        </form>

    </div>
</div>
<script>
    layui.use(['form', 'layer'],function() {

        $ = layui.jquery;
        var form = layui.form;
        layer = layui.layer;

        form.on('submit(add)',
            function(data) {
                console.log(data);
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

                //console.log($('input[name="gender"]:checked').val());

                // 真值表：
                // danger_mail  month_mail info_mail
                // 0               0       0           0    0
                // 0               0       1           1
                // 0               1       0           2    1
                // 0               1       1           3
                // 1               0       0           4
                // 1               0       1           5
                // 1               1       0           6
                // 1               1       1           7
                // console.log(data.field['danger_mail'])
                // if(!data.field['danger_mail']&&!data.field['month_mail']) data.field['info_mail']=0;
                // else if(!data.field['danger_mail']&&!data.field['month_mail']) data.field['info_mail']=0;
                // else if(!data.field['danger_mail']&&!data.field['month_mail']) data.field['info_mail']=0;
                // else if(!data.field['danger_mail']&&!data.field['month_mail']) data.field['info_mail']=0;
                // console.log(data.field['info_mail'])
                //
                 if(!data.field['danger_mail']) data.field['danger_mail']='off';
                if(!data.field['month_mail']) data.field['month_mail']='off';
                if(!data.field['info_mail']) data.field['info_mail']='off';

                //发异步，把数据提交给php
                $.ajax({
                    url:'{{URL::action('Admin\InfoController@mail')}}',
                    type:'post',
                    // data:{add_data:data.field},
                    data:data.field,
                    headers : {
                        'X-CSRF-TOKEN' : $("meta[name='csrf-token']").attr('content')
                    },
                    beforeSend:function () {
                        this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                    },
                    success:function(data){
                        if(data.status=='error'){
                            layer.msg('Error',{
                                icon:5//失败的表情
                                ,time:1000
                            })
                            return ;
                        }else{
                            layer.msg('Successful Add!',{
                                icon:6,//成功的表情
                                time:1000
                            },function(){
                                xadmin.father_reload();
                            });
                        }
                        return ;
                    },
                    error:function(data){
                        layer.msg('Error',{
                            icon:5//失败的表情
                            ,time:1000
                        })
                    }
                    // complete:function(){
                    //     // layer.close(this.layerIndex);
                    //     // xadmin.delay(1000);
                    //     xadmin.close();
                    //     // xadmin.father_reload();
                    // }
                })
                layer.alert("操作完成", {
                        icon: 6,
                        time:2000
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
                return false;
            });

    });
</script>

</body>

</html>
